const setLocalStorage = (name, value) => {
  sessionStorage.setItem(name, value);
};

const getLocalStorage = (name) => {
  return sessionStorage.getItem(name);
};

const clearLocalStorage = () => {
  sessionStorage.clear();
};

const setLocalStorageTrue = (name, value) => {
  localStorage.setItem(name, value);
};

const getLocalStorageTrue = (name) => {
  return localStorage.getItem(name);
};

const removeLocalStorageTrue = (name) => {
  return localStorage.removeItem(name);
};

const clearLocalStorageTrue = () => {
  localStorage.clear();
};

const mapGetLocalStorageKey = () => {
  const localStorageKeyInValue = {};
  for (const key in sessionStorage) {
    if (Object.prototype.hasOwnProperty.call(sessionStorage, key)) {
      localStorageKeyInValue[key] = sessionStorage[key];
    }
  }
  return localStorageKeyInValue;
};

const mapLocalStorageKey = (localStorage) => {
  localStorage && localStorage.length && localStorage.map(storageKey => {
    if (storageKey.jsonParse) {
      setLocalStorage(storageKey.localStorageKey, JSON.parse(storageKey.localStorageValue));
    } else if (storageKey.jsonStringify) {
      setLocalStorage(storageKey.localStorageKey, JSON.stringify(storageKey.localStorageValue));
    } else if (storageKey.jsonParseStringify) {
      setLocalStorage(storageKey.localStorageKey, JSON.parse(JSON.stringify(storageKey.localStorageValue)));
    } else {
      setLocalStorage(storageKey.localStorageKey, storageKey.localStorageValue);
    }
  });
};

export {
  setLocalStorage,
  getLocalStorage,
  clearLocalStorage,
  mapLocalStorageKey,
  mapGetLocalStorageKey,
  setLocalStorageTrue,
  getLocalStorageTrue,
  removeLocalStorageTrue,
  clearLocalStorageTrue
};
